﻿/*
 * Cratos Desktop
 * Cratos Cache Assembly Element Collection class
 * 
 * Copyright (c) 2011 Draco
 * 
 * This file is part of Cratos.
 * 
 * Cratos is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Cratos is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Cratos.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *       .==.        .==.
 *      //'^\\      //^'\\
 *     // ^ ^\(\__/)/^ ^^\\
 *    //^ ^^ ^/6  6\ ^^ ^ \\
 *   //^ ^^ ^/( .. )\^ ^ ^ \\
 *  // ^^ ^/\| V""V|/\^ ^ ^ \\
 * //^^/\/ /  '~~'  \ \/\^ ^ \\
 *  ------------------------------------
 *  HERE BE DRAGONS
 *  
 *  Johan Dercksen - johan@draco.co.za
 */
using System;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Generic;

namespace Cratos.Desktop
{
  /// <summary>
  /// Cache Assembly Element Collection class
  /// </summary>
  public class CacheAssemblyElementCollection : ConfigurationElementCollection
  {
    #region Class Constant declarations
    #endregion

    #region Class Event declarations
    #endregion

    #region Class Variable declarations
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public CacheAssemblyElementCollection() { }
    #endregion

    #region Class Properties
    /// <summary>
    /// Collection Type
    /// </summary>
    public override ConfigurationElementCollectionType CollectionType
    {
      get { return (ConfigurationElementCollectionType.BasicMap); }
    }

    /// <summary>
    /// Element Name
    /// </summary>
    protected override string ElementName
    {
      get { return("CacheAssembly");  }
    }

    /// <summary>
    /// Element
    /// </summary>
    /// <param name="serviceName">CacheAssembly Element Name</param>
    /// <returns>
    /// CacheAssembly Element corresponding to the input value
    /// </returns>
    new public CacheAssemblyElement this[string serviceName]
    {
      get { return ((CacheAssemblyElement)this.BaseGet(serviceName)); }
    }

    /// <summary>
    /// Element
    /// </summary>
    /// <param name="elementIndex">Add In Element index</param>
    /// <returns>
    /// Add In Element corresponding to the input value
    /// </returns>
    public CacheAssemblyElement this[int elementIndex]
    {
      get { return ((CacheAssemblyElement)this.BaseGet(elementIndex)); }
      set
      {
        // Remove the element if required
        if (this.BaseGet(elementIndex) != null) { this.BaseRemoveAt(elementIndex); }

        // Add the element to the collection
        this.BaseAdd(elementIndex, value);
      }
    }
    #endregion

    #region Class Methods
    /// <summary>
    /// Create a new element
    /// </summary>
    /// <returns></returns>
    protected override ConfigurationElement CreateNewElement()
    {
      // Create the new element required
      return(new CacheAssemblyElement());
    }

    /// <summary>
    /// Retrieve the specified elements key
    /// </summary>
    /// <param name="serviceElement">Service Element</param>
    /// <returns>
    /// Key of the specified element
    /// </returns>
    protected override Object GetElementKey(ConfigurationElement serviceElement)
    {
      // Retrieve the specified elements name
      return (((CacheAssemblyElement)serviceElement).Name);
    }

    /// <summary>
    /// Add a new element to the collection
    /// </summary>
    /// <param name="serviceElement">Service Element</param>
    public void Add(CacheAssemblyElement serviceElement)
    {
      // Add the element to the collection
      this.BaseAdd(serviceElement);
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
